import upyun from 'upyun'
import {getUpyunToken} from '../api/photo'

export function getClient() {
  const bucket = new upyun.Bucket('image-lhuo')
  function getHeaderSign(bucket, method, path) {
    let params = {bucket: bucket.bucketName, method: method, path: path}
    return getUpyunToken(params).then(function(response) {
      if (response.code !== 0) {
        console.error('gen header sign faild!')
        return
      }
      return response.data
    })
  }
  return new upyun.Client(bucket, getHeaderSign)
}
